package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Getter@Setter
@JsonIgnoreProperties({"handler", "json"})
public class Travel extends BaseDomain{
    public static final int STATE_REJECT = -1;//拒绝
    public static final int STATE_NORMAL = 0;//草稿
    public static final int STATE_WAIT = 1;//待发布
    public static final int STATE_RELEASE = 2;//已发布

    //标题
    private String title;

    //旅游时间
    @JsonFormat(pattern = "y-M-d",timezone ="GMT+8")//后台传给前台
    @DateTimeFormat(pattern = "y-M-d")//前台传给后台,不需要时区
    private Date travelTime;

    //人均消费
    private String perExpends;

    //旅游天数
    private Integer days;

    //旅游人数
    private Integer person;

    //作者
    private User author;
    //作则ID用来 接受 修改游记状态时 游记的作者
    private Long userId;
    //创建时间
    @JsonFormat(pattern = "y-M-d",timezone ="GMT+8")//后台传给前台
    @DateTimeFormat(pattern = "y-M-d")//前台传给后台,不需要时区
    private Date createTime;

    //发布时间
    @JsonFormat(pattern = "y-M-d",timezone ="GMT+8")//后台传给前台
    @DateTimeFormat(pattern = "y-M-d")//前台传给后台,不需要时区
    private Date releaseTime;

    //是否公开
    private Boolean isPublic;

    //地区
    private Region place;

    //封面
    private String coverUrl;

    //最后更新时间
    @JsonFormat(pattern = "y-M-d H:m:s",timezone ="GMT+8")//后台传给前台
    @DateTimeFormat(pattern = "y-M-d H:m:s")//前台传给后台,不需要时区
    private Date lastUpdateTime;

    //状态
    private Integer state = STATE_NORMAL;//默认是草稿状态

    //游记文本
    private TravelContent travelContent;

    //点赞次数
    private Integer likeCount ;

    //游记收藏次数
    private Integer collectCount;

    //游记评论数
    private Integer commentCount;

    private Integer viewCount;

    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }

    public String getStateName() {
        String state = "草稿";
        if (this.state == STATE_REJECT) {
            state = "拒绝";
        } else if (this.state == STATE_WAIT) {
            state = "待审核";
        } else if (this.state == STATE_RELEASE) {
            state = "已发布";
        }
        return state;
    }
}